package com.qmzy.lab05.controller;


import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qmzy.lab05.entity.Account;
import com.qmzy.lab05.entity.St;
import com.qmzy.lab05.service.DbService;
import com.qmzy.lab05.service.IAccountService;
import com.qmzy.lab05.service.IStService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjy
 * @since 2021-06-16
 */
@RestController
@RequestMapping("api/account")
public class AccountController {

    @Autowired
    private IAccountService service;



    @PreAuthorize("hasRole('USER')")
    @PostMapping("/update")
    public void updatePass(@RequestBody Account account){
        UpdateWrapper<Account> updateWrapper = new UpdateWrapper<Account>()
                .set("password",account.getPassword())
                .eq("id",account.getId());
        service.update(updateWrapper);
    }


    @GetMapping("/aclock")
    public Integer getIsClock(@RequestParam Integer id){
        Account account = service.getById(id);
        return account.getAclock();
    }


    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("/countNoClockIn")
    public Integer getCountNoClockIn(){
        QueryWrapper<Account> queryWrapper = new QueryWrapper<Account>().eq("clockin",0);
        return service.count(queryWrapper);
    }


    @PreAuthorize("hasRole('USER')")
    @GetMapping("/accheck")
    public Integer getCheck(){
        return 1;
    }

}
